﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Blackbird.Studio.ViewModel.EntityViewModels;

namespace Blackbird.Studio.View
{
    /// <summary>
    /// Interaction logic for EditableFramesetPreviewView.xaml
    /// </summary>
    public partial class EditableFramesetPreviewView
    {

        public EditableFramesetPreviewViewModel ViewModel { get { return (DataContext as EditableFramesetPreviewViewModel); } }

        public EditableFramesetPreviewView()
        {
            InitializeComponent();
            Activated += OnWindowActivated;
            Deactivated += OnWindowDeactivated;
        }


        private void OnWindowActivated(object sender, EventArgs e)
        {
            ViewModel.InitializeRenderer();
            CompositionTarget.Rendering += OnWindowRender;
        }

        

        private void OnWindowDeactivated(object sender, EventArgs e)
        {
            CompositionTarget.Rendering -= OnWindowRender;
            ViewModel.DeinitializeRenderer();
        }

        private void OnWindowRender(object sender, EventArgs e)
        {
            ViewModel.Render();
        }
    }
}
